<template>
	<view class="wap">
		<navbar :parameter='parameter'></navbar>
		<view class="list" v-if="lists.length > 0">
			<block v-for="(item,index) in lists " :key="index">
				<navigator class="list-item" :url="'/pages/accompanying/story_details?id='+item.id">
					<view class=" acea-row row-between-wrapper">
						<view class="title">{{item.title}}</view>
						<view class="time">{{item.createtime}}</view>
					</view>
					<view class="cont line2">{{item.content}}</view>
				</navigator>
			</block>
		</view>
		<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" v-else>
		</u-empty>
		<u-loadmore v-if="lists.length > 0" :status="status" line dashed @loadmore="loadmore" />
		<view class="btn-box" v-if="isShow">
			<navigator class="btn" url="/pages/accompanying/story_upload"> 新增陪诊故事 </navigator>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				parameter: {
					'navbar': '1',
					'return': '1',
					'title': '公益陪诊故事列表',
					'color': true,
					'class': 'on'
				},
				lists: [],
				status: 'loadmore',
				limit: 10,
				page: 1,
				total_num: '',
				isShow:true,
			};
		},
		onLoad(option) {
			this.id = option.id
			if(option.isShow){
				this.isShow = false
			}
		},
		onShow() {
			this.lists = [];
			this.list(this.id);
		},
		onReachBottom() {
			this.loadmore()
		},
		methods: {
			async list(id) {
				const res = await this.$myRequest({
					url: '/api/staff/storyLists',
					data: {
						page: this.page,
						limit: this.limit,
						staff_id: id,
						openid: uni.getStorageSync('openid')
					}
				})
				this.lists = [...this.lists, ...res.data.data];
				this.total_num = res.data.total_num;
			},
			loadmore() {
				console.log(11111)
				if (this.total_num == this.lists.length) {
					this.status = 'nomore';
				} else {
					this.status = 'loading';
					this.page++;
					this.list(this.id);
				}
				setTimeout(() => {
					if (this.total_num == this.lists.length) this.status = 'nomore';
					else this.status = 'loading';
				}, 2000)
			}
		},
		
	}
</script>

<style lang="scss" scoped>
	.wap {
		padding: 30rpx;
	}

	.list {
		padding: 0 30rpx;
		background-color: #fff;
		border-radius: 12rpx;
	}

	.list-item {
		padding: 30rpx 0;
		background-color: #fff;
		border-bottom: 1px solid #D9D9DA;
	}

	.list-item:last-of-type {
		border-bottom: none;
	}

	.list-item .title {
		font-size: 28rpx;
		font-weight: 700;
		color: #000;
	}

	.list-item .cont {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
		line-height: 1.8;
	}

	.list-item .time {
		font-size: 24rpx;
		color: #999999;
	}
	.btn-box {
		padding: 30rpx;
		padding-top: 40rpx;
	}
	
	.btn-box .btn {
		width: 100%;
		height: 80rpx;
		border-radius: 10rpx;
		line-height: 80rpx;
		text-align: center;
		background-color: #347DFE;
		color: #fff;
		font-size: 32rpx;
	}
</style>
